package cn.wit.summit.chwan.utils;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.telephony.TelephonyManager;

import pub.devrel.easypermissions.EasyPermissions;

import static android.content.Context.TELEPHONY_SERVICE;

/**
 * Created by tangbl on 2017/12/2 0002.
 */

public class AppInfoUtil {

    public static String getAppMac (Context context) {
        return GetPhoneAddressUtil.getAdresseMAC(context);
    }

    public static String getAppPkName (Context context) {
        try {
            return context.getPackageName();
        } catch (Exception e) {
            LogUtils.e("AppInfoUtil_PkName:"+e.getMessage());
        }
        return null;
    }

    @SuppressLint({"HardwareIds", "MissingPermission"})
    public static String getIMEI (Context context) {
        if (!EasyPermissions.hasPermissions(context, Manifest.permission.READ_PHONE_STATE)){
            return "";
        }
        return ((TelephonyManager) context.getSystemService(TELEPHONY_SERVICE)).getDeviceId();
    }

    public static String getAppVersionName (Context context) {
        try {
            String pkName = context.getPackageName();
            String versionName = context.getPackageManager().getPackageInfo(
                    pkName, 0).versionName;
            return versionName;
        } catch (Exception e) {
            LogUtils.e("AppInfoUtil_versionName:"+e.getMessage());
        }
        return null;
    }

    public static int getAppVersionCode (Context context) {
        try {
            String pkName = context.getPackageName();
            int versionCode = context.getPackageManager()
                    .getPackageInfo(pkName, 0).versionCode;
            return versionCode;
        } catch (Exception e) {
            LogUtils.e("AppInfoUtil_versionCode:"+e.getMessage());
        }
        return -1;
    }

    //获得设备型号
    public static String getDeviceModel() {
        String deviceName = Build.MODEL;
        return deviceName;
    }
}
